package edu.hawaii.senin.iclouds.util;

import java.io.File;

/**
 * Provides file access utilities for xml files.
 * 
 * @author Pavel Senin
 */
public class Utils {
  /**
   * Contains the xml file extension.
   */
  public static final String xml = "xml";

  /**
   * Get the extension of a file.
   * 
   * @param f the file.
   * @return the string representation of the extension to the file.
   */
  public static String getExtension(File f) {
    String ext = null;
    String s = f.getName();
    int i = s.lastIndexOf('.');

    if (i > 0 && i < s.length() - 1) {
      ext = s.substring(i + 1).toLowerCase();
    }
    return ext;
  }

  /**
   * Converts time to string representation.
   * 
   * @param l time in milliseconds.
   * @return string human readable representation.
   */
  public static String time2Strthis(Long l) {
    Long hours = l / 3600000L;
    Long minutes = (l - 3600000L * hours) / 60000;
    Long sec = (l - 60000 * hours) / 1000;
    return hours.toString() + " h, " + minutes.toString() + " m, " + sec.toString() + " sec.";
  }
}
